﻿//小区状况通用下拉框的获取
var uri = document.location.search;//接收页面传值
var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
var P_ReportNumber11 = uri.substr(i);//截取问号前面的值
$(function () {
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Dictionary/GetHouseTypeList",
        data: {
            Dmenuid: [7, 8, 9, 10, 11, 12, 13, 27]
        },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                $("option").remove();
                $(data).each(function (i, obj) {
                    $(obj).each(function (j, item) {
                        switch (item.Dmenuid) {
                         
                            case 7:
                                $("#C_closeID").append("<option  value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 8:
                                $("#C_buildingID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 9:
                                $("#C_trafficID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 10:
                                $("#C_afforestID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 11:
                                $("#C_volumeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 12:
                                $("#C_stallID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                   break;
                            case 13:
                                $("#C_propertyID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                            case 27:
                                $("#C_sourceID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                break;
                        }
                    })
                })
            }
        },
        error: function (e) {
        },
        complete: function () {
        }
    })
})

//小区状况的数据添加
function insertCommunity() {
    var C_project = $("#C_project").val();                   // --项目案名   
    var C_sourceID = $("#C_sourceID option:checked").attr("value");     // --来源编号
    var C_source = $("#C_source").val()                      //--来源情况编写
    var C_closeID = $("#C_closeID option:checked").attr("value");       //-小区封闭性编号
    var C_buildingID = $("#C_buildingID option:checked").attr("value"); //居住小区楼宇构成编号
    var C_trafficID = $("#C_trafficID option:checked").attr("value");   //交通组织方式编号
    var C_afforestID = $("#C_afforestID option:checked").attr("value"); //景观及绿化编号
    var C_volumeID = $("#C_volumeID option:checked").attr("value");     //容积率编号
    var C_stallID = $("#C_stallID option:checked").attr("value");       //车位编号
    var C_propertyID = $("#C_propertyID option:checked").attr("value")  //-物业公司编号
    var C_else = $("#C_else").val();		                 //其他


    var parms = {
        C_project: C_project,        // --项目案名   
        C_sourceID: C_sourceID,      // --来源编号
        C_source: C_source,          //--来源情况编写
        C_closeID: C_closeID,        //-小区封闭性编号
        C_buildingID: C_buildingID,  //居住小区楼宇构成编号
        C_trafficID: C_trafficID,    //交通组织方式编号
        C_afforestID: C_afforestID,  //景观及绿化编号
        C_volumeID: C_volumeID,      //容积率编号
        C_stallID: C_stallID,        //车位编号
        C_propertyID: C_propertyID,  //-物业公司编号
        C_else: C_else   ,            //其他
        P_ReportNumber:P_ReportNumber11  //报告号
    }
    $.ajax({
        type: "post",
        url: ApiUrl + "api/Community/Postinsert",
        data: parms,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data == true) {
                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }
            }
        },
        error: function (e) {
            layer.msg('服务器链接超时!', { icon: 0, time: 1000 });
        },
        complete: function () {

        }
    })
}
//数据回填
$(function () {
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Community/SelectByid",
        data: {
            P_ReportNumber: P_ReportNumber11
        },
        async: false,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    $("#P_ReportNumber").val(data.P_ReportNumber)
                    $("#C_project").val(data.C_project)
                    $("#C_sourceID").val(data.C_sourceID)
                    $("#C_source").val(data.C_source)
                    $("#C_closeID").val(data.C_closeID)
                    $("#C_buildingID").val(data.C_buildingID)
                    $("#C_trafficID").val(data.C_trafficID)
                    $("#C_afforestID").val(data.C_afforestID)
                    $("#C_volumeID").val(data.C_volumeID)
                    $("#C_stallID").val(data.C_stallID)
                    $("#C_propertyID").val(data.C_propertyID)
                    $("#C_else").val(data.C_else)
                    $("#C_state").val(data.C_state)
                }
            }
        },
        error: function (e) {
            layer.msg('提交失败', '#Hidden1');
        },
        complete: function () {

        }
    })
})